﻿using Application.MainModule.CitiesManagement;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Domain.MainModule.Cities;
using Domain.MainModule.Entities;
using Infraestructure.CrossCutting.IoC;

namespace Application.MainModule.Tests
{
    /// <summary>
    ///This is a test class for CityManagementServiceTest and is intended
    ///to contain all CityManagementServiceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CityManagementServiceTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }

            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for AddCity
        ///</summary>
        [TestMethod()]
        public void AddCity_Invoke_Test()
        {
            //Arrange
            ICityManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ICityManagementService>();
            Guid cityId = Guid.NewGuid();
            City city = new City()
            {
                CityId = cityId,
                Name = "ciudad gotica"
            };
            City result = null;

            //Act
            target.AddCity(city);

            //Assert
            result = target.FindCityByName("ciudad gotica");
            Assert.IsNotNull(result);
            Assert.AreEqual(cityId, result.CityId);
        }

        /// <summary>
        ///A test for ChangeCity
        ///</summary>
        [TestMethod()]
        public void ChangeCityTest()
        {
            //Arrange
            ICityManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ICityManagementService>();
            City city = null;
            City result = null;

            //Act
            city = target.FindCityByName("buenos aires");
            city.Addresses = new Domain.Core.Entities.TrackableCollection<Address>()
            {
                new Address()
                {
                    Street = "calle 13"
                }
            };
            target.ChangeCity(city);

            //Assert
            result = target.FindCityByName("buenos aires");
            Assert.IsNotNull(result);
            Assert.AreEqual("calle 13", result.Addresses[0].Street);
        }

        /// <summary>
        ///A test for FindCityByName
        ///</summary>
        [TestMethod()]
        public void FindCityByNameTest()
        {
            //Arrange
            ICityManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ICityManagementService>();
            City city = null;

            //Act
            city = target.FindCityByName("balcarce");

            //Assert
            Assert.IsNotNull(city);
            Assert.AreEqual("balcarce", city.Name);
        }
    }
}
